package com.lzq.his.service;

import com.lzq.his.domain.Dept;
import com.lzq.his.mapper.DeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class DeptService {

    @Autowired
    private DeptMapper deptMapper;

    public List<Dept> selectAll() {
        return deptMapper.selectByExample(null);
    }


    public void deleteById(String id) {
        deptMapper.deleteByPrimaryKey(Integer.parseInt(id));
    }

    public void save(Dept dept) {
        if (dept.getId() == null) {
            Random random = new Random();
            dept.setId(random.nextInt());
            deptMapper.insert(dept);
        } else {
            deptMapper.updateByPrimaryKeySelective(dept);
        }
    }
}
